package com.aircms.controller.admin;

import com.aircms.common.ServerResponse;
import com.aircms.controller.BaseAdminController;
import com.aircms.pojo.UserRole;
import com.aircms.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户角色
 * @author air
 * @create 2018-06-26 下午2:33
 */
@RestController
@RequestMapping(value = "auth/userRole")
public class UserRoleAdminController extends BaseAdminController {

    @Autowired
    private IUserRoleService iUserRoleService;

    /**
     * Display a listing of the resource.
     *
     * @return
     */
    @GetMapping(value = (""))
    public ServerResponse index() {
        return ServerResponse.resResponse();
    }


    /**
     * Show the form for creating a new resource.
     *
     * @return
     */
    @GetMapping(value = "create")
    public ServerResponse create(UserRole userRole) {

        return ServerResponse.resResponse();
    }


    /**
     * Store a newly created resource in storage.
     *
     * @return
     */
    @PostMapping(value = "")
    public ServerResponse store() {

        return ServerResponse.resResponse();
    }


    /**
     * Display the specified resource.
     *
     * @param id
     * @return
     */
    @GetMapping(value = "{id}")
    public ServerResponse show(@PathVariable Integer id) {

        return ServerResponse.resResponse();
    }


    /**
     * Show the form for editing the specified resource.
     *
     * @param id
     * @return
     */
    @GetMapping(value = "{id}/edit")
    public ServerResponse edit(@PathVariable Integer id) {

        return ServerResponse.resResponse();
    }


    /**
     * Update the specified resource in storage.
     *
     * @return
     */
    @RequestMapping(value = "{id}", method = {RequestMethod.PUT, RequestMethod.PATCH})
    public ServerResponse update(@PathVariable Integer id) {

        return ServerResponse.resResponse();
    }


    /**
     * Remove the specified resource from storage.
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "{id}")
    public ServerResponse destroy(@PathVariable Integer id) {

        return ServerResponse.resResponse();
    }

    @GetMapping("getUserRole/{userId}")
    public ServerResponse getUserRole(@PathVariable Integer userId) throws Exception{
        try {
            return iUserRoleService.getUserRole(userId);
        }catch (Exception e){
            this.errorLog(this.getClass(),e);
            throw new Exception("查询失败");
        }
    }
}
